import java.util.Stack;

public class demo4 {
    public boolean validateStackSequences(int[] pushV, int[] popV) {
        int x=0;
        Stack<Integer>stack=new Stack<>();
        for (int i=0;i<pushV.length;i++) {
            stack.add(pushV[i]);
            while (!stack.isEmpty()&& x<popV.length&&stack.peek()==popV[x]) {
                stack.pop();
                x++;
            }
        }
        if(!stack.isEmpty())return false;
        return true;
    }
}
